home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-04-30 | 6.1 KB | 182 lines | [TEXT/MPS ] |
- {[j=20/53/1$]}
-
- {-------------------------------------------------------------------------------------------}
- {$S ASelCommand}
-
- PROCEDURE TAreaSelector.IAreaSelector(itsView: TFracAppView; itsDocument: TFracAppDocument);
-
- { Initialize the selector object itself by calling ICommand. Also set the boolean that says
- we constrain the mouse, so that our TrackConstrain method gets called. }
-
- BEGIN
- { initialize normal parts of command }
- SELF.INoChangesCommand(cMouseCommand, itsDocument, itsView, NIL);
-
- fConstrainsMouse := TRUE; { do the constrain to match to screen. }
-
- fOwnerView := itsView; { save the view for use in tracking. }
- fPlotWidth := itsDocument.GetPlotWidth;
- fPlotHeight := itsDocument.GetPlotHeight;
-
- END; { TAreaSelector.IAreaSelector }
-
- {-------------------------------------------------------------------------------------------}
- {$S ADoCommand}
-
- FUNCTION TAreaSelector.TrackMouse(aTrackPhase: TrackPhase; VAR anchorPoint, previousPoint,
- nextPoint: VPoint;
- mouseDidMove: Boolean): TCommand; OVERRIDE;
-
- { Track the mouse while the button is down. This is overridden so we can make sure that the
- selection is cleared when we start tracking, and properly set when we are done tracking. }
-
- VAR
- selPatHandle: PatHandle;
- tempRect: Rect;
-
- BEGIN
- TrackMouse := SELF; { Make sure we return something valid. }
-
- CASE aTrackPhase OF
- trackPress: BEGIN
- fOwnerView.SetSelection(gZeroRect, kRedraw); { clear rect, there isn’t one. }
- END;
-
- trackRelease: BEGIN
- Pt2Rect(VPtToPt(anchorPoint), VPtToPt(nextPoint), tempRect);
- fOwnerView.SetSelection(tempRect, kRedraw);
- END;
- END; { Case on aTrackPhase }
- END; { TAreaSelector.TrackMouse }
-
- {-------------------------------------------------------------------------------------------}
- {$S ADoCommand}
-
- PROCEDURE TAreaSelector.TrackFeedback(anchorPoint, nextPoint: VPoint; turnItOn,
- mouseDidMove: Boolean); OVERRIDE;
-
- { Track the mouse giving the feedback of a different rectangle kind. This is so we can use
- the selection pattern to give a preferred rectangle. The selection pattern comes out of
- temporary memory so as to not fail needlessly. }
-
- VAR
- selBoy: Rect;
- selPatHandle: PatHandle;
-
- BEGIN
- IF mouseDidMove THEN BEGIN {the pen is already in patXOR mode,
- black, one wide}
- selPatHandle := GetPattern(kSelPattern); { get the pattern we use. }
- IF selPatHandle <> NIL THEN { use our pattern if available. }
- PenPat(selPatHandle^^); { set pen pattern to our selection kind.
- }
-
- Pt2Rect(VPtToPt(anchorPoint), VPtToPt(nextPoint), selBoy);
- FrameRect(selBoy);
- END;
- END; { TAreaSelector.TrackFeedback }
-
- {-------------------------------------------------------------------------------------------}
- {$S ADoCommand}
-
- PROCEDURE TAreaSelector.TrackConstrain(anchorPoint, previousPoint: VPoint;
- VAR nextPoint: VPoint); OVERRIDE;
-
- { Constrain the mouse to a rectangle that is the same proportion as the document, so we can
- make the selection match better without having to guess at the length or width, or scaling
- the chosen rect to fit the document. Small piece chosen will blow up to fit easily. This
- will make it easier to choose a selection that gives a 1:1 aspect ratio. This also
- chooses which direction the mouse has moved, deciding which is larger in order to decide
- the direction to constrain. }
-
- VAR
- newWidth, newHeight: LongInt;
- mouseRatio, plotRatio: Real;
-
- PROCEDURE ChangeWidth;
-
- BEGIN
- { Get the new width as a positive number, a displacement that is constrained. }
-
- newWidth := ABS(nextPoint.v - anchorPoint.v) * fPlotWidth DIV fPlotHeight;
-
- { Decide which quadrant we are in, moving the right direction. }
-
- IF nextPoint.h < anchorPoint.h THEN
- newWidth := - newWidth;
-
- { Actually change the final point to pass back. }
-
- nextPoint.h := anchorPoint.h + newWidth; { add offset to get new pt. }
- END;
-
- PROCEDURE ChangeHeight;
-
- BEGIN
- { Get the new height as a positive number, a displacement that is constrained. }
-
- newHeight := ABS(nextPoint.h - anchorPoint.h) * fPlotHeight DIV fPlotWidth;
-
- { Decide which quadrant we are in, moving the right direction. }
-
- IF nextPoint.v < anchorPoint.v THEN
- newHeight := - newHeight;
-
- { Actually change the final point to pass back. }
-
- nextPoint.v := anchorPoint.v + newHeight; { add offset to get new pt. }
- END;
-
- PROCEDURE PinPoint;
- { Pin the rectangle to the edge of the document. }
-
- VAR
- constrainRect: VRect;
-
- BEGIN
- {$Push} {$H-}
- SetVRect(constrainRect, 0, 0, fPlotWidth, fPlotHeight);
- {$Pop}
- PinVRect(constrainRect, nextPoint);
- END;
-
- BEGIN
- mouseRatio := ABS((nextPoint.h - anchorPoint.h) / (nextPoint.v - anchorPoint.v));
- plotRatio := fPlotWidth / fPlotHeight;
-
- { The deltaX, deltaY can be thought of as a rect too. If the ratio of sides on
- that rect (width/height) is greater than the ratio of width/height of the
- plot rectangle, then we need to grow the height of the rect. If it is less,
- we need to grow the width. This is a ratio of sides to decide which way to
- grow. We grow to make the new rect still touch the mouse position. It can be
- thought of as the rectangle being thicker than tall wanting to grow the tall
- part in a constrained way, and the corollary for the width. }
-
- IF mouseRatio > plotRatio THEN BEGIN { constrain height to new value. }
- ChangeHeight;
- PinPoint;
- ChangeWidth;
- END
- ELSE BEGIN { constrain width to new value. }
- ChangeWidth;
- PinPoint;
- ChangeHeight;
- END;
- END; { TAreaSelector.TrackConstrain }
-
- {-------------------------------------------------------------------------------------------}
- {$S AFields}
-
- PROCEDURE TAreaSelector.Fields(PROCEDURE DoToField(fieldName: Str255; fieldAddr: Ptr;
- fieldType: Integer)); OVERRIDE;
-
- BEGIN
- DoToField('TFastFracAppEngine', NIL, bClass);
- DoToField('fOwnerView', @fOwnerView, bObject);
- DoToField('fPlotHeight', @fPlotHeight, bObject);
- DoToField('fPlotWidth', @fPlotWidth, bObject);
-
- { Print fields of anscestors }
- INHERITED Fields(DoToField);
- END;
-